package com.company;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

public class Main {

    private static int sResult = 0;

    public static void main(String[] args) {
        ExecutorService executorService = Executors.newFixedThreadPool(4);

        Callable<Integer> callable = () -> {
            for (int i=0;i<50;i++){
                Thread.sleep(100);
                sResult ++;
                System.out.println("working...");
            }
            return sResult;
        };

        Future<Integer> submit = executorService.submit(callable);
        try {
            System.out.println("result="+submit.get());
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
    }
}
